package com.cqie.hospitalescort.controller;

import com.cqie.hospitalescort.DTO.OrderDTO;
import com.cqie.hospitalescort.VO.OrderVO;
import com.cqie.hospitalescort.entity.MedOrder;
import com.cqie.hospitalescort.model.Result;
import com.cqie.hospitalescort.service.MedOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单信息 前端控制器
 * </p>
 *
 * @author gdy
 * @since 2025-02-18
 */
@RestController
@RequestMapping("/order")
@Api(value = "订单管理", tags = {"订单管理"})
public class MedOrderController extends BaseController {

    @Autowired
    private MedOrderService medOrderService;

    @GetMapping("/list")
    @ApiOperation(value = "订单列表")
    public Result<List<OrderVO>> orderList(@RequestParam(required = false) Integer status,
                                           @RequestParam Boolean isAdmin,
                                           @RequestParam(required = false) Boolean isEscort){
        return response(medOrderService.orderList(status, isAdmin, isEscort));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "订单详情")
    public Result<OrderVO> detail(@RequestParam String orderCode){
        return response(medOrderService.detail(orderCode));
    }

    @PostMapping("/start")
    @ApiOperation(value = "用户发起订单")
    public Result<String> startOrder(@RequestBody OrderDTO dto){
        return response(medOrderService.startOrder(dto));
    }

    @GetMapping("/take")
    @ApiOperation(value = "陪诊员接取订单")
    public Result<Void> takeOrder(@RequestParam String orderCode){
        medOrderService.takeOrder(orderCode);
        return response();
    }

    @GetMapping("/pay")
    @ApiOperation(value = "支付")
    public Result<Void> payOrder(@RequestParam String orderCode){
        medOrderService.payOrder(orderCode);
        return response();
    }

    @GetMapping("/complete")
    @ApiOperation(value = "完成订单")
    public Result<Void> completeAppointment(@RequestParam String orderCode){
        medOrderService.completeAppointment(orderCode);
        return response();
    }

    @GetMapping("/cancel")
    @ApiOperation(value = "用户取消订单")
    public Result<Void> cancelOrder(@RequestParam String orderCode){
        medOrderService.cancelOrder(orderCode);
        return response();
    }

    @GetMapping("/delete")
    @ApiOperation(value = "管理员删除订单")
    public Result<Void> deleteOrder(@RequestParam String orderCode){
        medOrderService.deleteOrder(orderCode);
        return response();
    }

}
